﻿using System;
using MockDataTransferObject;
using MockBusiness;
using System.Globalization;

namespace Presentation.UserControl
{
    public partial class MenuClient : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] != null)
            {
                User user = (User)Session["user"];
                ProfileLink.NavigateUrl = String.Format(CultureInfo.CurrentCulture, "../UserProfile.aspx?uname={0}&rname={1}", user.UserName, user.Role.RoleName);

                if (user.Role.RoleName == "Contractor")
                {
                    TimesheetMenuLink.Visible = true;
                    AddTimesheetLink.Visible = true;
                    ManageTimesheetLink.Visible = true;
                    ContractBusiness contractBusiness = ContractBusiness.RetrieveInstance();
                    ClientBusiness clientBusiness = ClientBusiness.RetrieveInstance();

                    object contractIdObject = contractBusiness.GetContractIdByContractorUserId(user.UserId);
                    if (contractIdObject != null && contractIdObject is Guid)
                    {
                        Guid contractId = Guid.Parse(contractIdObject.ToString());
                        object username = clientBusiness.GetClientUserNameByContractId(contractId);
                        if (username != null)
                        {
                            MyClientProfileLink.NavigateUrl = String.Format(CultureInfo.CurrentCulture, "../UserProfile.aspx?uname={0}&rname=Client", username);
                            MyClientProfileLink.Visible = true;
                        }
                    }
                }
                if (user.Role.RoleName == "Client")
                {
                    TimesheetMenuLink.Visible = true;
                    ApproveTimesheetLink.Visible = true;
                }
                if (user.Role.RoleName == "Consultant")
                {
                    ContractMenuLink.Visible = true;
                    ViewContractLink.Visible = true;
                    ReportMenuLink.Visible = true;
                }
            }
        }
    }
}
